package domain;


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.xml.sax.SAXException;

import net.sf.jxls.reader.ReaderBuilder;
import net.sf.jxls.reader.XLSReadStatus;
import net.sf.jxls.reader.XLSReader;
import domain.Gdzc;

/**
 * TODO 必须填写该类用途
 *
 * 长沙正步科技有限公司 kl 创建于 2014-6-5
 */
public class JxlsUtile {
	
	private static JxlsUtile  jxls;
	
	private List gdzcs;
	
	public static synchronized JxlsUtile getJxls() {
		if(jxls == null){
			jxls = new JxlsUtile();
		}
		return jxls;
	}
	public static void setJxls(JxlsUtile jxls) {
		JxlsUtile.jxls = jxls;
	}

//public static void main(String[] args) {
//	//JxlsUtile.getJxls().readData("");
//	JxlsUtile jxls=new JxlsUtile();
//	jxls.readData("");
//}

	public List readData(File f) {
		// TODO Auto-generated method stub
		InputStream inputXML = new BufferedInputStream(getClass().getResourceAsStream("gdzc.xml"));  
		XLSReader mainReader;
		try {
			mainReader = ReaderBuilder.buildFromXML( inputXML );
			InputStream inputXLS = new BufferedInputStream(new FileInputStream(f));  
			//InputStream inputXLS = new BufferedInputStream(getClass().getResourceAsStream(path));  
			Gdzc gdzc = new Gdzc();  
			// Department hrDepartment = new Department();  
		    gdzcs = new ArrayList();  
			Map beans = new HashMap();  
			//beans.put("gdzc", gdzc);  
			beans.put("gdzcs", gdzcs);  
			XLSReadStatus readStatus = mainReader.read( inputXLS, beans); 
			//return gdzcs;
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			e.printStackTrace();
		}  
		return gdzcs;
	}

}
